<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0" />
    <title>美策平台</title>
    <link rel="icon" type="image/png" href="/img/icon.png">
    <link rel="stylesheet" type="text/css" href="../datepicker/jquery-ui.min.css">
    <link rel="stylesheet" type="text/css" href="../css/app.css">
    <link rel="stylesheet" type="text/css" href="../css/index.css">
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script type="text/javascript" src="/pc/js/all.js"></script>
    <script src="http://g.tbcdn.cn/mtb/lib-flexible/0.3.4/??flexible_css.js,flexible.js"></script>
</head>
<style>
.staffPageActive{
    background-color: #3B7DF2 ! important;
    color: #fff ! important;
}
.none{
    display: none;
}
.nullCetner{
    text-align: center;
    position: absolute;
    top: 6.666667rem;
    transform: translate(-50%, -50%);
    left: 50%;
    color: #c3c3c3;
}
</style>
<body>
<!--
    制作者：九哥
    页面：找工人页面
    时间：2019-03-01
-->





<!----------找工人页面---------->
<div id="staffPage"><!--此ID页面切换用-->
    <div id="staffTitle">
        <b>找工人</b>
        <img src="../images/return.png" id="staffRtn">
    </div>
    <div id="staffPpt">
        <img src="/uploads/20190227/companyppt.png">
    </div>
    <div id="staffDetail">
        <div style="height:10px;"></div>
        <div class="menu">
            <p class="letTitle">推荐</p>
            <div id="staffMore">更多部门</div>
        </div>
        <div class="list"></div>
    </div>
</div>
<!----------找工人页面---------->





<!----------错误提示---------->
<div id="errMsg"></div>
<!----------错误提示---------->
</body>
<script type="text/javascript" src="../js/indexPageChange.js"></script>
<script type="text/javascript" src="../js/index.js"></script>
<script>
    $(function() {
        getDeparts();
    });

    /**
     * 获取部门列表
     * */
    function getDeparts(){
        var userInfo = cacheGet('userInfo');
        if (!userInfo) {
            getErrMsg('没有登陆','/h5/login/login.html'); return
        }
        if (userInfo.type==1) {
            getErrMsg('您不是企业','/h5/'); return
        }
        var formData = {
            app_access:app_access,
            token:userInfo.token,
            type:userInfo.type
        };
        $.ajax({
            type:'get',
            url: '/api/home/staff/cate',
            data:formData,
//            dataType:'json',
//            contentType: "application/json",
//            async: false,
            success: function (result) {
                //console.log(result); return
                if (result.code === 200) {
                    var data = result.data;
                    console.log(data)
                    var div = '';
                    for (let i = 0; i < data.length; i++) {
                        if (i === 0) {
                            div += `<div data-id="${data[i].id}" class="staffMenu staffPageActive" onclick="comMenu(${data[i].id})">${data[i].name}</div>`
                        } else {
                            if (i > 8) {
                                div += `<div data-id="${data[i].id}" class="staffMenu none" onclick="comMenu(${data[i].id})">${data[i].name}</div>`;
                            } else {
                                div += `<div data-id="${data[i].id}" class="staffMenu" onclick="comMenu(${data[i].id})">${data[i].name}</div>`;
                            }
                        }


                    }
                    list(data[0].id);
                    $('.letTitle').after(div)
                }
            }
        });
    }

    $('#staffMore').click(function() {
        var menu = $('.menu');
        console.log(menu);
        menu.find('.staffMenu').css('display', 'block');
        $(this).remove();
    });
    
    function list(id) {
        $.ajax({
            url: '/api/home/staff',
            type:'get',
            data: {cate: id},
//            dataType:'json',
//            contentType: "application/json",
//             async: false,
            success: function (result) {
//                console.log(result); return
                $('.list').children().remove();
                if (result.code === 200) {
                    var data = result.data;
                    var div = '';
                    if (data.length > 0) {
                        for (let i = 0; i < data.length; i++) {
                        div += `<div class="staff toStaffShow" onclick="toStaffShow(${data[i].uid})" data-id="${data[i].id}" data-uid="${data[i].uid}">
                                    <img src="${data[i].image}">
                                    <p>${data[i].name}</p>
                                </div>`
                        }
                        $('.list').append(div)
                    } else {
                        var div = '<div class="nullCetner">啊噢，暂时没找到呢</div>'
                        $('.list').append(div)
                    }
                   
                } else {
                    alertMsg(data.msg)
                }
                // var img=new Image();
                // img.src= '';
                // img.onload=function(){
                // }  
            },
            error: function(err) {
                alertMsg(err)
            }
        });
    }
    
    function comMenu(id) {
        console.log(id)
        var menu = $('.menu');
        var ids = menu.find(`.staffMenu[data-id=${id}]`);
        ids.addClass('staffPageActive')
        ids.siblings('.staffMenu').removeClass('staffPageActive')
        list(id)
    } 
    function toStaffShow(uid) {
        var ids = {
            uid: uid
        }   
        window.location.href = 'staffShow.html?ids=' + JSON.stringify(ids)
    }
    </script>
</html>